package com.ithuameng.admin.app.system.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ithuameng.admin.app.system.model.Role;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * Role mapper
 *
 * @author ithuameng
 */
public interface RoleMapper extends BaseMapper<Role> {

    /**
     * 根据用户ID查询角色
     *
     * @param userId 用户ID
     * @return 角色列表
     */
    @Select({
            "<script>",
            "SELECT DISTINCT r.id, r.name, r.role_key,r.seq, r.create_time, r.create_by, r.update_time, r.update_by FROM t_role r",
            "LEFT JOIN t_user_role ur ON ur.role_id = r.id",
            "LEFT JOIN t_user u ON (u.id = ur.user_id and u.deleted='N')",
            "WHERE r.deleted='N' and ur.user_id=#{userId}",
            "</script>"
    })
    List<Role> selectRolePermissionByUserId(Long userId);
}
